#include <os/lock.h>
#include <os/sched.h>
#include <atomic.h>

void spin_lock_init(spin_lock_t *lock)
{
    /* TODO */
}

int spin_lock_try_acquire(spin_lock_t *lock)
{
    /* TODO */
}

void spin_lock_acquire(spin_lock_t *lock)
{
    /* TODO */
}

void spin_lock_release(spin_lock_t *lock)
{
    /* TODO */
}

void do_mutex_lock_init(mutex_lock_t *lock)
{
    /* TODO */
    if(lock->lock.status==LOCKED)
    	return ;
    if(lock->block_queue.next!=&lock->block_queue)
    init_list_head(&lock->block_queue);
    lock->lock.status=UNLOCKED;
}

void do_mutex_lock_acquire(mutex_lock_t *lock)
{
    /* TODO */
    if(lock->lock.status==LOCKED)
    	{do_block(&current_running->list,&lock->block_queue);
    	lock->lock.status=LOCKED;}
	else
	lock->lock.status=LOCKED;
}

void do_mutex_lock_release(mutex_lock_t *lock)
{
    /* TODO */
    if(lock->lock.status==LOCKED){
    //while(lock->block_queue.next!=&lock->block_queue)
    do_unblock(lock->block_queue.next);
	lock->lock.status=UNLOCKED;}
}
